Output the total number of String Characters [migrated]

Posted by Programmerwannabe on Programmers See other posts from Programmers or by Programmerwannabe
Published on 2012-04-13T19:03:48Z Indexed on 2012/04/13 23:44 UTC
Read the original article Hit count: 150

Filed under:

My Question is what method should I use if I wanted to get the total number of characters a user inputs? without using arrays, i tried using .length() but it did not return all characters say from the first and lastname, it only returned the first name.

Here's an example of my code. (Please dont laugh im really new in programming :) )

System.out.print("Enter your first and last name: ");
String yourName = keyboard.next();
System.out.println("Your name has a total of " + yourName.length() + " numbers");

what happened was if i enter say "Neo Matrix" it would only return 3.

I appreciate any help. thank you!

© Programmers or respective owner

Related posts about java